package com.example.demo.topic.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.topic.entity.TNoteApprove;
import com.example.demo.topic.service.TNoteApproveService;
import com.example.demo.util.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 发帖审核表; 前端控制器
 * </p>
 *
 * @author 涛
 * @since 2024-08-01
 */
@RestController
@RequestMapping("/tNoteApprove")
@Tag(name = "tNoteApprove", description = "发帖审核相关")
public class TNoteApproveController {

    @Autowired
    private TNoteApproveService tNoteApproveService;

    /**
     * 获取发帖审核模块列表
     */
    @GetMapping("/getNoteList")
    @Operation(summary = "获取发帖审核列表接口", description = "获取发帖审核列表接口")
    public Result<?> getNoteList(@RequestParam(value = "current", required = false, defaultValue = "1")Integer current,
                                 @RequestParam(value = "size", required = false, defaultValue = "10")Integer size,
                                 TNoteApprove note){
        Page<TNoteApprove> page = new Page<>(current,size);
        QueryWrapper<TNoteApprove> queryWrapper = new QueryWrapper<>(note);
        return Result.ok(tNoteApproveService.page(page,queryWrapper));
    }

    /**
     * 根据ID查询帖子信息
     */
    @GetMapping("/getNoteById")
    @Operation(summary = "根据id查询帖子审核明细", description = "根据id查询帖子审核明细")
    public Result<?> getNoteById(Integer id){
        return Result.ok(tNoteApproveService.getById(id));
    }

    /**
     * 修改帖子信息
     */
    @PutMapping("/updateNote")
    @Operation(summary = "根据id修改帖子审核明细", description = "根据id修改帖子审核明细")
    @Transactional
    public Result<?> updateNote(@RequestBody TNoteApprove note){
        return Result.ok(tNoteApproveService.updateById(note));
    }

    /**
     * 新增帖子信息
     */
    @PostMapping("/addNote")
    @Operation(summary = "帖子审核", description = "帖子审核")
    public Result<?> addNote(@RequestBody TNoteApprove note){
        return Result.ok(tNoteApproveService.save(note));
    }

    /**
     * 删除帖子信息
     */
    @DeleteMapping("/deleteNoteById")
    @Operation(summary = "删除帖子审核记录", description = "删除帖子审核记录")
    @Transactional
    public Result<?> deleteNoteById(Integer id){
        return Result.ok(tNoteApproveService.removeById(id));
    }
}

